package com.okami.thread;


import java.util.concurrent.locks.ReentrantLock;

/**
 * @author: TanJingyu
 * @create: 2021-01-16 16:52
 **/
class MainTest {
    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();

        test(lock);

        new Thread(() -> test(lock)).start();

        new Thread(() -> test(lock)).start();
    }

    public static void test(ReentrantLock lock) {
        try {
            lock.lock();

            System.out.println(Thread.currentThread().getName());
        } finally {
            lock.unlock();
        }
    }
}
